package com.sky.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.sky.annotation.AutoFill;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;

import io.lettuce.core.dynamic.annotation.Param;

@Mapper
public interface CategoryMapper {

  /* 
   * 分页查询
   */
  List<Category> page(@Param("name") String name, @Param("type") Integer type);

  /* 
   * 新增分类
   */
  @AutoFill(value = OperationType.INSERT)
  @Insert("insert into category (name, type, sort, status, create_time, update_time, create_user, update_user) values (#{name}, #{type}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
  void add(Category category);

  /* 
   * 分类查询
   */
  @Select("select * from category where type = #{type} order by sort")
  List<Category> list(@Param("type") Integer type);

  /* 
   * 根据id删除分类
   */
  @Delete("delete from category where id = #{id}")
  void delete(Long id);

  /* 
   * 是否禁用
   */
  @Update("update category set status = #{status} where id = #{id}")
  void status(String status, String id);

  /* 
   * 修改分类
   */
  @AutoFill(value = OperationType.UPDATE)
  @Update("update category set name = #{name}, type = #{type}, sort = #{sort} where id = #{id}")
  void update(CategoryDTO categoryDTO);

  
} 
